//
//  UIBarButtonItem+DXWBarButtonItem.m
//  pandaTV
//
//  Created by 淡馨慰 on 16/8/20.
//  Copyright © 2016年 淡馨慰. All rights reserved.
//

#import "UIBarButtonItem+DXWBarButtonItem.h"

@implementation UIBarButtonItem (DXWBarButtonItem)


+ (instancetype)barButtonItemWithImage:(UIImage *)image higtLightedImage:(UIImage *)higtLightedImage target:(id)target action:(SEL)action
{

    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setImage:image forState:UIControlStateNormal];
    [btn setImage:higtLightedImage forState:UIControlStateHighlighted];
    [btn sizeToFit];
    [btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    
    //保证点击的范围在图片之中
    UIView *btnView = [[UIView alloc]initWithFrame:btn.bounds];
    [btnView addSubview:btn];
    
    UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithCustomView:btnView];
    return item;
}

+ (instancetype)barButtonItemWithImage:(UIImage *)image target:(id)target action:(SEL)action
{
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
    [btn setImage:image forState:UIControlStateNormal];
    [btn sizeToFit];
    [btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    
    //保证点击的范围在图片之中
    UIView *btnView = [[UIView alloc]initWithFrame:btn.bounds];
    [btnView addSubview:btn];
    
    UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithCustomView:btnView];
    return item;
}


@end
